package lastfm
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
  import lastfm.events.ApiEvent;
  import lastfm.events.ArtistInfoEvent;
	
	/**
   * ...
   * @author Roman Marchenko
   */
  public class ArtistInfo extends EventDispatcher
  {

    public function ArtistInfo(target:IEventDispatcher = null)
    {
      super(target);
    }

    public function loadInfo (artist: String): void
    {
      trace("ArtistInfo.loadInfo: " + artist);
      var api: Api = new Api;
      api.addEventListener(ApiEvent.OK, onOK);
      api.artistGetInfo(artist);
    }

    private function onOK (event: ApiEvent): void
    {
      trace("ArtistInfo.onOK");
      var newevent: ArtistInfoEvent = new ArtistInfoEvent(ArtistInfoEvent.OK);
      newevent.artist = event.response["artist"];
      newevent.url = event.response["url"];
      newevent.image = event.response["image"];
      newevent.stats = event.response["stats"];
      newevent.bio = event.response["bio"];
      newevent.similar = event.response.similar;
      dispatchEvent(newevent);
    }
  }

}